package com.ymatou.iapi.commission.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.commission.parameter.ReturnCommissionRateRequestBean;
import com.ymatou.iapi.commission.service.ReturnCommissionRateServiceCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;

public class Ts_ReturnCommissionRate {
	
	private static ReturnCommissionRateRequestBean returnCommissionRateRequestBean;
	private static ReturnCommissionRateServiceCall returnCommissionRateServiceCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退佣接口");
	}

	@Before
	public void caseUp() {
		returnCommissionRateRequestBean = new ReturnCommissionRateRequestBean();
		returnCommissionRateServiceCall = new ReturnCommissionRateServiceCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(returnCommissionRateServiceCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ReturnCommissionRate_001() {
		Logger.start(true,"获取订单的返佣信息");
		try {
			Logger.comment("前置数据准备");
			long orderId = 11111;
			String orderPaidTime = "2018-03-22 14:13:17";
			long userId = 1234;
			long sellerId = 22233;
			int countryId = 1;
			
			Logger.comment("前置数据准备完毕");
			
			returnCommissionRateRequestBean.setOrderId(orderId);
			returnCommissionRateRequestBean.setNewCustomer(false);
			returnCommissionRateRequestBean.setNewSeller(false);
			returnCommissionRateRequestBean.setOrderPaidTime(orderPaidTime);
			returnCommissionRateRequestBean.setUserId(userId);
			returnCommissionRateRequestBean.setSellerId(sellerId);
			returnCommissionRateRequestBean.setCountryId(countryId);
			
			returnCommissionRateServiceCall.setData(returnCommissionRateRequestBean);
			returnCommissionRateServiceCall.callService();

			Logger.verifyEquals("success", 
					returnCommissionRateServiceCall.getJSONReturnData().getString("resultMessage"), 
					"验证resultMessage");
			Logger.verifyEquals("0", 
					returnCommissionRateServiceCall.getJSONReturnData().getString("resultCode"), 
					"验证resultCode");
			Logger.verifyEquals(true, 
					returnCommissionRateServiceCall.getJSONReturnData().getBoolean("success"), 
					"验证success");
			
			//返佣接口返回走配置，固定输出
			JSONObject orderReturnCommission = returnCommissionRateServiceCall.getOrderReturnCommission();
			Logger.verifyEquals(0, 
					orderReturnCommission.getInt("returnCommissionRate"), 
					"验证returnCommissionRate");
			Logger.verifyEquals("bizConfig", 
					orderReturnCommission.getString("strategyId"), 
					"验证strategyId");
			Logger.verifyEquals(0, 
					orderReturnCommission.getInt("refundFlag"), 
					"验证refundFlag");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ReturnCommissionRate_002() {
		Logger.start(true,"支付时间不传");
		try {
			Logger.comment("前置数据准备");
			long orderId = 11111;
			long userId = 1234;
			long sellerId = 22233;
			int countryId = 1;
			
			Logger.comment("前置数据准备完毕");
			
			returnCommissionRateRequestBean.setOrderId(orderId);
			returnCommissionRateRequestBean.setNewCustomer(false);
			returnCommissionRateRequestBean.setNewSeller(false);
			returnCommissionRateRequestBean.setUserId(userId);
			returnCommissionRateRequestBean.setSellerId(sellerId);
			returnCommissionRateRequestBean.setCountryId(countryId);
			
			returnCommissionRateServiceCall.setData(returnCommissionRateRequestBean);
			returnCommissionRateServiceCall.callService();

			Logger.verifyEquals("orderPaidTime:may not be null", 
					returnCommissionRateServiceCall.getJSONReturnData().getString("resultMessage"), 
					"验证resultMessage");
			Logger.verifyEquals("2", 
					returnCommissionRateServiceCall.getJSONReturnData().getString("resultCode"), 
					"验证resultCode");
			Logger.verifyEquals(false, 
					returnCommissionRateServiceCall.getJSONReturnData().getBoolean("success"), 
					"验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
